package org.thulearn.htmlparser;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;

public class ParserUtil {
	static public String parseLink(String html) {
		String result = "";
		Parser parser = Parser.createParser(html, "utf-8"); 
		try {
			NodeList linkList = parser.extractAllNodesThatMatch(new NodeFilter() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

				public boolean accept(Node node) {
					if (node instanceof LinkTag) {
						return true;
					} else {
						return false;
					}
				}
			});

			if(linkList.size() > 0) {
				LinkTag link = (LinkTag) linkList.elementAt(0);
				result = link.getStringText().trim() + " " + link.extractLink().trim();
			}
		} catch (ParserException e) {
			e.printStackTrace();
		}
		
		return result;
	}
}
